Use this BCP script to generate CSV file:
bcp "SELECT ''ID'', ''Username'' UNION ALL SELECT CAST(u.ID as varchar(10)),u.USERNAME from DavidTest.dbo.DavidUser u" queryout "c:\output.csv" -c -t"," -r"\n" -SServerName -T
If you want to run in SSMS, you can use:
USE MASTER
GO
DECLARE @query varchar(4000)
SET @query = '"SELECT...."';
EXEC xp_cmdshell @bcpOut
GO
for more info:
http://msdn.microsoft.com/en-us/library/aa174646(v=sql.80).aspx
马齿徒增 又长一岁 <->
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.